/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.chris.webservice.ws.impl;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.chris.webservice.manager.intf.ILocationManager;
import com.chris.webservice.ws.common.OmcConstants;
import com.chris.webservice.ws.dto.Device;
import com.chris.webservice.ws.dto.Devices;
import com.chris.webservice.ws.dto.RequesterID;
import com.chris.webservice.ws.intf.ILocationService;
import com.chris.webservice.ws.result.dto.CallerInfo;
import com.chris.webservice.ws.result.dto.PosInfo;
import com.chris.webservice.ws.result.dto.PosInfos;
import com.chris.webservice.ws.result.dto.Result;

/**
 *
 * @author Chris
 */
@Stateless
@Remote
@WebService(name = "LocationService", targetNamespace = OmcConstants.NS, serviceName = "ws")
//@Interceptors({ExceptionInterceptor.class, SecurityInterceptor.class})
//@Interceptors({ExceptionInterceptor.class})
public class LocationServiceImpl implements ILocationService {

    @EJB
    private ILocationManager locationManager;
    protected static Logger logger = LoggerFactory
            .getLogger(LocationServiceImpl.class);

    @WebMethod(operationName = "GetPositionRequest")
    public Result GetPositionRequest(
            @WebParam(name = "requesterID") RequesterID requesterID,
            @WebParam(name = "devices") Devices devices) {
//        logger.info("str = " + str);
//    	System.out.println("Username:" + requesterID.getUsername());
//    	System.out.println("Password:" + requesterID.getPassword());
//    	
//    	if (devices != null) {
//    		List<Device> list = devices.getDevice();
//    		if (list != null && list.size() > 0) {
//    			for (Device d : list) {
//    				System.out.println("id:" + d.getID());
//        	    	System.out.println("postType:" + d.getPosType());
//    			}
//    		}
//    	}
//    	Result result = new Result();
//    	PosInfos posInfos = new PosInfos();
//    	List<PosInfo> list = new ArrayList<PosInfo>();
//    	
//    	PosInfo PosInfo1 = new PosInfo();
//    	PosInfo1.setPositionResult(0);
//    	PosInfo1.setId("13392896319");
//    	PosInfo1.setPosType("GPS");
//    	PosInfo1.setLocalTime("20100903163407");
//    	PosInfo1.setLongitude("114.05789");
//    	PosInfo1.setLatitude("23.13793");
//    	list.add(PosInfo1);
//    	
//    	PosInfo PosInfo2 = new PosInfo();
//    	PosInfo2.setPositionResult(0);
//    	PosInfo2.setId("13342820019");
//    	PosInfo2.setPosType("GPSCell");
//    	PosInfo2.setLocalTime("20100825125230");
//    	PosInfo2.setLongitude("113.33036");
//    	PosInfo2.setLatitude("23.13793");
//    	list.add(PosInfo2);
//    	
//    	posInfos.setPosInfo(list);
//    	
//    	CallerInfo callerInfo = new CallerInfo();
//    	callerInfo.setCallerId("weizhi");
//    	
//    	result.setReturnCode("11");
//    	result.setPosInfos(posInfos);
//    	result.setCallerInfo(callerInfo);
    	
    	
    	Result result = locationManager.getLocation(requesterID, devices);
    	
        return result;
    }

}
